<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Javris Ticket Export - 连接测试</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            max-width: 600px;
            margin: 50px auto;
            padding: 20px;
        }
        .test-section {
            border: 1px solid #ddd;
            padding: 20px;
            margin: 20px 0;
            border-radius: 5px;
        }
        .success { color: green; }
        .error { color: red; }
        button {
            background: #007bff;
            color: white;
            border: none;
            padding: 10px 20px;
            border-radius: 3px;
            cursor: pointer;
            margin: 5px;
        }
        button:hover { background: #0056b3; }
        .result {
            margin-top: 10px;
            padding: 10px;
            background: #f5f5f5;
            border-radius: 3px;
        }
    </style>
</head>
<body>
    <h1>Javris Ticket Export - 连接测试</h1>
    
    <div class="test-section">
        <h3>1. 测试OPTIONS请求（预检）</h3>
        <button onclick="testOptions()">测试OPTIONS</button>
        <div id="optionsResult" class="result"></div>
    </div>
    
    <div class="test-section">
        <h3>2. 测试POST请求（发送Token）</h3>
        <button onclick="testPost()">测试POST</button>
        <div id="postResult" class="result"></div>
    </div>
    
    <div class="test-section">
        <h3>3. 测试GET请求（应该失败）</h3>
        <button onclick="testGet()">测试GET</button>
        <div id="getResult" class="result"></div>
    </div>

    <script>
        const API_URL = 'http://dev.com/jarvis-ticket.php';
        
        async function testOptions() {
            const resultDiv = document.getElementById('optionsResult');
            resultDiv.innerHTML = '测试中...';
            
            try {
                const response = await fetch(API_URL, {
                    method: 'OPTIONS',
                    headers: {
                        'Content-Type': 'application/json',
                    }
                });
                
                resultDiv.innerHTML = `
                    <div class="success">✅ OPTIONS请求成功</div>
                    <div>状态码: ${response.status}</div>
                    <div>状态文本: ${response.statusText}</div>
                `;
            } catch (error) {
                resultDiv.innerHTML = `
                    <div class="error">❌ OPTIONS请求失败</div>
                    <div>错误: ${error.message}</div>
                `;
            }
        }
        
        async function testPost() {
            const resultDiv = document.getElementById('postResult');
            resultDiv.innerHTML = '测试中...';
            
            try {
                const response = await fetch(API_URL, {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json',
                    },
                    body: JSON.stringify({
                        token: 'test_token_12345'
                    })
                });
                
                const result = await response.json();
                
                if (response.ok) {
                    resultDiv.innerHTML = `
                        <div class="success">✅ POST请求成功</div>
                        <div>状态码: ${response.status}</div>
                        <div>响应: ${JSON.stringify(result, null, 2)}</div>
                    `;
                } else {
                    resultDiv.innerHTML = `
                        <div class="error">❌ POST请求失败</div>
                        <div>状态码: ${response.status}</div>
                        <div>响应: ${JSON.stringify(result, null, 2)}</div>
                    `;
                }
            } catch (error) {
                resultDiv.innerHTML = `
                    <div class="error">❌ POST请求失败</div>
                    <div>错误: ${error.message}</div>
                `;
            }
        }
        
        async function testGet() {
            const resultDiv = document.getElementById('getResult');
            resultDiv.innerHTML = '测试中...';
            
            try {
                const response = await fetch(API_URL, {
                    method: 'GET'
                });
                
                const result = await response.text();
                
                if (response.status === 405) {
                    resultDiv.innerHTML = `
                        <div class="success">✅ GET请求正确被拒绝</div>
                        <div>状态码: ${response.status} (Method Not Allowed)</div>
                        <div>响应: ${result}</div>
                    `;
                } else {
                    resultDiv.innerHTML = `
                        <div class="error">❌ 意外响应</div>
                        <div>状态码: ${response.status}</div>
                        <div>响应: ${result}</div>
                    `;
                }
            } catch (error) {
                resultDiv.innerHTML = `
                    <div class="error">❌ GET请求失败</div>
                    <div>错误: ${error.message}</div>
                `;
            }
        }
    </script>
</body>
</html>
